package huaweiod.third;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * 字符串拼接
 * https://fcqian.blog.csdn.net/article/details/135232122?spm=1001.2014.3001.5502
 */
public class C_StringSplicing {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        char[] chars = str.toCharArray();
        boolean[] visit = new boolean[chars.length];
        int len = in.nextInt();
        Set<String> set = new HashSet<>();
        dfs("", (char) 0, len, chars, visit, set);
        System.out.println(set.size());
    }

    private static void dfs(String s, char pre, int len, char[] chars, boolean[] visit, Set<String> set) {
        if (len == s.length()) {
            set.add(s);
            return;
        }
        for (int i = 0; i < chars.length; i++) {
            if (!visit[i] && chars[i] != pre) {
                visit[i] = true;
                dfs(s + chars[i], chars[i], len, chars, visit, set);
                visit[i] = false;
            }
        }
    }
}
